from django.shortcuts import render
from django.http import HttpResponse,JsonResponse
from .. models import Users,Types,Goods,Cart,Address,Order,OrderInfo
from . TypesViews import GetTypesAll
from . UserViews import uploads
from django.contrib.auth.decorators import permission_required

# 订单主页
@permission_required('myadmin.show_order',raise_exception=True)
def index(request):
    obj = Order.objects.filter()
    # 上下文
    context = {'orderlist':obj}
    return render(request,'admin/order/index.html',context)

# 订单状态
@permission_required('myadmin.del_order',raise_exception=True)
def fahuo(request):
    if request.is_ajax():
        try:
            ob = Order.objects.get(id=request.GET['id'])
            ob.status = 3 
            ob.save()
            return JsonResponse({'code':1,'msg':' 已发货,待收货'})
        except:
            ob.status = 0
            return JsonResponse({'code':0,'msg':'已取消 '})
    else:
        # 返回一个404的错误页面
        raise Http404("Poll does not exist")